/** 
 * TEMPERATURE UNITS
 * Contains 
 * 
 * Each unit is set up as:
 * 
 * UNITS {
 * 
 * 	-- Returns value in same units --
 * 	public double toUnits(double value){
 * 		return value;
 * 	}
 * 
 * 	-- Returns value in other units --
 * 	-- One method for each type in category --
 * 	-- Example: UNITS = INCHES, value = 18, Convert toFeet, Return = 1.5 (Feet)
 * 	public double toOtherUnits(double value){
 * 		return value ( / or * ) ####;
 * 	}
 * 		
 * 	-- Converts value value of Unit type sourceUnit into UNITS type --
 * 	-- Example: UNITS = INCHES, value = 1.5, sourceUnit = FEET, return = 18 (Inches)
 * 	public double convert (double value, EnglishUnit sourceUnit){
 * 		return sourceUnit.toUnits(value);
 *	}
 * }
 */

package umuc.cmsc495.mach2.unit;

/**
 * @author Michael Swann
 * 
 */
public enum TemperatureUnit {
    CELSIUS {
	public double toCelsius(double value) {
	    return value;
	}

	public double toKelvin(double value) {
	    return value + 273.15;
	}

	public double toFahrenheit(double value) {
	    return (value * 1.8) + 32;
	}

	public double toRankine(double value) {
	    return (value + 273.15) * 1.8;
	}

	public double convert(double value, TemperatureUnit sourceUnit) {
	    return sourceUnit.toCelsius(value);
	}
    },

    KELVIN {
	public double toCelsius(double value) {
	    return value - 273.15;
	}

	public double toKelvin(double value) {
	    return value;
	}

	public double toFahrenheit(double value) {
	    return (value * 1.8) - 459.67;
	}

	public double toRankine(double value) {
	    return value * 1.8;
	}

	public double convert(double value, TemperatureUnit sourceUnit) {
	    return sourceUnit.toKelvin(value);
	}
    },

    FAHRENHEIT {
	public double toCelsius(double value) {
	    return (value - 32) * 5 / 9;
	}

	public double toKelvin(double value) {
	    return (value + 459.67) * 5 / 9;
	}

	public double toFahrenheit(double value) {
	    return value;
	}

	public double toRankine(double value) {
	    return value + 459.67;
	}

	public double convert(double value, TemperatureUnit sourceUnit) {
	    return sourceUnit.toFahrenheit(value);
	}
    },

    RANKINE {
	public double toCelsius(double value) {
	    return (value - 491.67) * 5 / 9;
	}

	public double toKelvin(double value) {
	    return value * 5 / 9;
	}

	public double toFahrenheit(double value) {
	    return value - 459.67;
	}

	public double toRankine(double value) {
	    return value;
	}

	public double convert(double value, TemperatureUnit sourceUnit) {
	    return sourceUnit.toRankine(value);
	}
    };

    /**
     * @param sourceValve
     *            Value in Source Units
     * @param sourceUnit
     *            Source Unit Type
     * @return Value in Target Units
     */
    public abstract double toCelsius(double value);

    public abstract double toKelvin(double value);

    public abstract double toFahrenheit(double value);

    public abstract double toRankine(double value);

    public abstract double convert(double sourceValve, TemperatureUnit sourceUnit);
}
